<?php
session_name(DicomScience);
session_start();

# Resolving 
$servername = getenv ('SERVER_NAME'); //IP ADDRESS
$requesturi = getenv ('REQUEST_URI'); // NOT NECESSARY _ YET

$requesturi = getenv ('REQUEST_URI');
$array = explode ( '../controller/writeBlog.php', $requesturi );#zeigt "/tt/"

if ($array[0] = " ") {
	// Installation Direcory of DicomScience is the Web - root Dir
	$science_dir = $servername;
	
} else {
	// Installation Directory of DicomScience is not Web root dir
	$science_dir = $servername."/".$array[0];
}
$rss_dir = $science_dir."/rss";

/*
 * Now generate the XML Newsfeed
 */
	
$news = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>
<feed version=\"0.3\" xmlns=\"http://w3.org/2005/Atom\" xml:lang=\"de\">
<title>DicomScience News</title>
<link rel=\"alternate\" type=\"text/html\" href=\"http://$science_dir\" />
<tagline>DicomScience News</tagline>
<copyright>Copyright 2008 dicomscience.org - visit the webpage for further details on licensing and usage.</copyright>

";
require_once('../includes/gset.php');
require ('../includes/database/connect.php');

$sql_getblogs = "SELECT id_blog, blog.id_staff, blogdate, message, lastname, firstname FROM blog, staff WHERE blogdate > '$voreinerwoche' AND blog.id_staff = staff.id_staff ORDER BY (blogdate) DESC;";
$getblogs = mysql_query($sql_getblogs);
	
require ('../includes/database/closedb.php');
	
while ($blog = mysql_fetch_object($getblogs)){
	$idblog = $blog->id_blog;
	$editor = $blog->id_staff;
	$blogdate = $blog->blogdate;
	$message = $blog->message;
	$editorlastname = $blog->lastname;
	$editorfirstname = $blog->firstname;
			
	$aktuelle_zeit = time();
	$lessoneminute = $aktuelle_zeit - 60;
	$lessonehour = $aktuelle_zeit - 3600;
	$lessoneday = $aktuelle_zeit - 86400;
	$yesterday = $aktuelle_zeit - 172800;
	$week = $aktuelle_zeit - 604800;
	$twoweeks = $aktuelle_zeit - 1209600;
	$month = $aktuelle_zeit - 2419200;
	$twomonths = $aktuelle_zeit - 4838400;
	$halfyear = $aktuelle_zeit - 14515200;
	$year = $aktuelle_zeit - 29030400;	
					
	if ($blogdate > $lessoneminute){
		$display_blogdate = $nls_lessoneminute;
	} elseif ($blogdate > $lessonehour){
		$display_blogdate = $nls_lessonehour;
	} elseif ($blogdate > $lessoneday){
		$display_blogdate = $nls_lessoneday;
	} elseif ($blogdate > $yesterday) {
		$display_blogdate = $nls_yesterday;
	} elseif ($blogdate > $week){
		$display_blogdate = $nls_week;
	} elseif ($blogdate > $twoweeks){
		$display_blogdate = $nls_twoweeks;
	} elseif ($blogdate > $month){
		$display_blogdate = $nls_month;
	} elseif ($blogdate > $twomonths){
		$display_blogdate = $nls_twomonths;
	} elseif ($blogdate > $halfyear){
		$display_blogdate = $nls_halfyear;
	} elseif ($blogdate > $year){
		$display_blogdate = $nls_year;
	} else {
		$display_blogdate = $nls_older;
	}
	
	$news = $news."
	<entry>
		<title><![CDATA[$message]]></title>
		<link rel=\"alternate\" type=\"text/html\" href=\"http://$science_dir/includes/blogView.php\"/>
		<author><name>$editorfirstname $editorlastname</name></author>
		
		<content type=\"text/html\" mode=\"escaped\" xml:lang=\"de-de\"><![CDATA[
		<p><b>$editorfirstname $editorlastname</b></p>
		<p>$message</p>
		]]> />
		</content>
	</entry>
	";
	
	} #endWhile
	
	$news = $news."
	</feed>
	";
	
	$rssnews=fopen('../rss/news.xml','w');
		fwrite ($rssnews, $news);
	fclose($rssnews);	

	# returns the rss for a browser
	echo ("$news");
?>